package _220327;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.OutputStreamWriter;
import java.io.PrintWriter;
import java.io.StreamTokenizer;
import java.util.ArrayList;
import java.util.List;

/**
 * @author ShadowLim
 * @create 2022-03-27-11:31
 */

public class 大臣的旅费 {
    static boolean[] vis;
    static List<Integer> list = new ArrayList<>();
    static int max = 0, n;  // 最大距离 城市数量
    static List<Node>[] leng;
    static int depth = 0;   // 最深节点

    public static void main(String[] args) throws IOException {
        // 快读
        StreamTokenizer in = new StreamTokenizer(new BufferedReader(new InputStreamReader(System.in)));
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        in.nextToken();
        n = (int)in.nval;   // 城市数量
        vis = new boolean[n];
        leng = new ArrayList[n];
        for (int i = 0; i < n; i++) {
            leng[i] = new ArrayList<>();
        }
        int[] arr = new int[n];
        for (int i = 0; i < n - 1; i++) {   // n - 1 条公路
            in.nextToken();
            int a = (int)in.nval;
            in.nextToken();
            int b = (int)in.nval;
            in.nextToken();
            int c = (int)in.nval;
            // 城市编号从0开始
            leng[a - 1].add(new Node(b - 1, c));    // 城市 a 的邻接城市是b 且两者之间距离为 c
            leng[b - 1].add(new Node(a - 1, c));    // 无向图
        }

        vis[0] = true;  // 从首都开始出发
        dfs(0, 0);
        vis[0] = false; // 回溯

        vis[depth] = true;
        dfs(depth, 0);
        vis[depth] = false;

        // 距离为 (10 + 1) + (10 + 2) +...+ (10 + n) = 10*n + (1+2+3+4...+n)
        double average = ((double)max + 1) / (double)2 + 10;
        double value = average * max;
        out.println((int)value);
        out.flush();    // 刷新
    }

    private static void dfs(int i, int curDistance) {
        if (curDistance > max) {
            max = curDistance;
            depth = i;
        }
        for (int k = 0; k < leng[i].size(); k++) {
            int team = leng[i].get(k).x;
            if (leng[i].get(k).distance > 0 && !vis[team]) {
                vis[team] = true;
                dfs(team, curDistance + leng[i].get(k).distance);
                vis[team] = false;
            }
        }
    }

    static class Node {
        int x;  // 邻接城市编号
        int distance;

        public Node(int x, int distance) {
            this.x = x;
            this.distance = distance;
        }
    }
}
